﻿using System;
public class Node<T>
{
    public T Data { get; set; }
    public Node<T> Next { get; set; }
    public Node(T x)
    {
        Next = null; Data = x;
    }
}
public class GenericList<T>
{
    private Node<T> head, tail;
    public GenericList() { head = tail = null; }
    public Node<T> Head
    {
        get { return head; }
    }
    public void Add(T t)
    {
        Node<T> Now = Head;
        Node<T> New = new Node<T>(t);
        if (head == null)
        {
            head = tail = New;
        }
        else
        {
            tail.Next = New;
            tail = New;
        }
    }
    public void ForEach(Action<T> action)
    {
        Node<T> Now = Head;
        while (Now != null)
        {
            action(Now.Data);
            Now = Now.Next;
        }
    }
}

namespace _1_GenericList
{
    class Program
    {
        static void Main(string[] args)
        {
            GenericList<int> list = new GenericList<int>();
            Console.WriteLine("请输入整数的数量");
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine("请每行输入一个整数");
            for (int i = 1; i <= n; i++)
            {
                int x = int.Parse(Console.ReadLine());
                list.Add(x);
            }
            int Max = -2147483648, Min = 2147483647, Sum = 0;
            Action<int> getMax = (x => Max = (x > Max ? x : Max));
            Action<int> getMin = (x => Min = (x < Min ? x : Min));
            Action<int> getSum = (x => Sum += x);
            list.ForEach(getMax);
            list.ForEach(getMin);
            list.ForEach(getSum);
            Console.WriteLine("Max is {0} Min is {1} Sum is {2}", Max, Min, Sum);
        }
    }
}
